package com.kaibes.admin.api;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.kaibes.web.admin.IconBox;
import com.kaibes.web.api.ApiLinkService;
import com.kaibes.web.api.ApiLinkUtils;
import com.kaibes.web.thymeleaf.ThymeleafConfig;

@Configuration
public class ApiLinkConfig implements InitializingBean {

    @Autowired
    private ThymeleafConfig webConfig;
    @Autowired
    private ApiLinkService apiLinkService;
    
    // ======================
    @Bean
    public IconBox apiBox() {
        IconBox iconBox = new IconBox() {

            @Override
            public void update() {
                setCount(apiLinkService.listApi().size());
            }
        };
        iconBox.setSort(1);
        iconBox.setName("接口总数");
        iconBox.setClassAppend("bg-primary");
        iconBox.setIcon("ion-at");
        iconBox.setHref("/admin/api-link/api");
        return iconBox;
    }
    
    @Bean
    public IconBox linkBox() {
        IconBox iconBox = new IconBox() {

            @Override
            public void update() {
                setCount(apiLinkService.listLink().size());
            }
        };
        iconBox.setSort(2);
        iconBox.setName("页面总数");
        iconBox.setClassAppend("bg-secondary");
        iconBox.setIcon("ion-link");
        iconBox.setHref("/admin/api-link/link");
        return iconBox;
    }

	@Override
	public void afterPropertiesSet() throws Exception {
		webConfig.putStaticVariable("ApiLinkUtils", ApiLinkUtils.class);
	}
    
}
